package com.example.kx038;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * 网格视图
 */
public class MainActivity extends AppCompatActivity {

    private int[] pictures = new int[]{R.drawable.fs,R.drawable.img03};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        GridView gridView = findViewById(R.id.gridView1);
        List<Map<String, Object>> listItem = new ArrayList<>();

        for (int picture : pictures) {
            Map<String, Object> map = new HashMap<>();
            map.put("image", picture);
            listItem.add(map);
        }

        System.out.println(R.id.image);

        SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, listItem, R.layout.cell, new String[]{"image"}, new int[]{R.id.image});

        gridView.setAdapter(simpleAdapter);


    }
}